package com.evaluation.kexingcp.psycho.evaluation.sys.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.evaluation.kexingcp.common.core.util.R;
import com.evaluation.kexingcp.common.log.annotation.SysLog;
import com.evaluation.kexingcp.psycho.evaluation.sys.entity.EvaluationInquiryCategoryEntity;
import com.evaluation.kexingcp.psycho.evaluation.sys.service.EvaluationInquiryCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.evaluation.kexingcp.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 用户咨询方向
 *
 * @author kexingcp
 * @date 2024-09-23 16:20:28
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/evaluationInquiryCategory" )
@Tag(description = "evaluationInquiryCategory" , name = "用户咨询方向管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EvaluationInquiryCategoryController {

    private final  EvaluationInquiryCategoryService evaluationInquiryCategoryService;

    /**
     * 分页查询
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page")
    public R getEvaluationInquiryCategoryPage() {
        return R.ok(evaluationInquiryCategoryService.list());
    }


    /**
     * 通过id查询用户咨询方向
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}")
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(evaluationInquiryCategoryService.getById(id));
    }

    /**
     * 新增用户咨询方向
     * @param evaluationInquiryCategory 用户咨询方向
     * @return R
     */
    @Operation(summary = "新增用户咨询方向" , description = "新增用户咨询方向" )
    @SysLog("新增用户咨询方向" )
    @PostMapping
    public R save(@RequestBody EvaluationInquiryCategoryEntity evaluationInquiryCategory) {
        return R.ok(evaluationInquiryCategoryService.save(evaluationInquiryCategory));
    }

    /**
     * 修改用户咨询方向
     * @param evaluationInquiryCategory 用户咨询方向
     * @return R
     */
    @Operation(summary = "修改用户咨询方向" , description = "修改用户咨询方向" )
    @SysLog("修改用户咨询方向" )
    @PutMapping
    public R updateById(@RequestBody EvaluationInquiryCategoryEntity evaluationInquiryCategory) {
        return R.ok(evaluationInquiryCategoryService.updateById(evaluationInquiryCategory));
    }

    /**
     * 通过id删除用户咨询方向
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除用户咨询方向" , description = "通过id删除用户咨询方向" )
    @SysLog("通过id删除用户咨询方向" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(evaluationInquiryCategoryService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param evaluationInquiryCategory 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    public List<EvaluationInquiryCategoryEntity> export(EvaluationInquiryCategoryEntity evaluationInquiryCategory,Long[] ids) {
        return evaluationInquiryCategoryService.list(Wrappers.lambdaQuery(evaluationInquiryCategory).in(ArrayUtil.isNotEmpty(ids), EvaluationInquiryCategoryEntity::getId, ids));
    }
}